<?php
include 'header.php';

$username = $this->session->userdata('username');
$id_user = $this->session->userdata('id_user');
?>
<div style="margin-left:20px; margin-top: 60px;">
<h2>Daftar Produk</h2>
</div>
<?php


if(count($produk)){
		foreach($produk as $rows){
	
	//var_dump($rows);
	  ?>
<div class="panel panel-primary" style="margin-right:10px">
  <!-- Default panel contents -->
  <div class="panel-heading">
  </div>
  <div class="panel-body">
   <div class="hero-unit">
		<div class="media">
			<a class="pull-left" href="#">
			<img class="media-object" src="http://localhost/<?php echo $rows['gambar']; ?> " height="100" alt="" onclick="gambar(<?php echo $rows['id_produk'];?>)" title="klik untuk melihat review">
			</a>
			<div class="media-body">
				<h4 class="media-heading"><?php echo $rows['nama_produk']; ?></h4>
				<?php 
				echo $rows['ket_produk'];
				?>
				</div>
				<p> 
				<?php
				echo 'Harga: Rp '.$rows['harga'];
				?>
				</p>
				<p>
				Tags:
				
				<?php
				foreach($rows['tag'] as $tag){
				?>
				<a href="<?php echo base_url().'index.php/produk/link_tag/'.$tag['keyword']; ?>">
				<?php
				echo '#';
				echo $tag['keyword'];
				?>
				</a>
				<?php
				}
				?>
				
				</p>
		</div>
		<?php
		if($id_user){
		if($id_user != 1){
		if($cart != null){
	?>
	<a class="btn btn-primary btn-large" href="<?php echo base_url().'index.php/cart/insert_cart/'.$rows['id_produk'].'/'.$cart->id_cart; ?>">Add to cart</a>
	<?php
	} else {
	
	}
	} else {
	}
	}
	?>
	
	<form action="<?php echo base_url().'index.php/produk/insert_review/'.$rows['id_produk']?>" method="post" >
      <p></p>

      <p>
      Komentar :
		</p>
		
	<p><input type="text" name="komentar_baru" placeholder="Beri komentar"></p>
		<p><button class="btn btn-primary btn-large">Beri komentar</button></p>

		</form>
		
   </div>
</div>

</div>

<?php
}
	
}

?>
<div id="modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="background-color: white;opacity: 1;width: 500px;margin-left: 430px;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3 id="myModalLabel">Review Produk</h3>
    </div>
    <div class="modal-body">
        <div class="form-horizontal" >			
			<div class="control-group" id="isi_komen">
			</div>
			
		</div>
		
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </div>
</div>

<script>
$(document).ready();
	function gambar(id){
	$('#isi_komen').empty();
	$.post('<?php echo base_url(); ?>index.php/produk/get_komen/',{
		id_komen: id
			}, 
			function(data){
			$.each(data['komen'], function(key, value) {				
				var komen = '<p>'+data['komen'][key].review+'</p>';
				komen += '<p>'+data['komen'][key].waktu_komen+'</p>';
				komen += '<hr size="5" color="#000000" shade></hr>';
				$('#isi_komen').append(komen);
            });
				
				$('#modal').modal('show');
				
        }, 'json');
	}
</script>